home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12680 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  56 lines

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help!  Can't read input from keyboard!
  5. Date: 1 Apr 1996 22:40 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <1APR199622404442@erich.triumf.ca>
  9. References: <4jq0ts$5mh@taniemarie.solon.com>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4jq0ts$5mh@taniemarie.solon.com>, seebs@taniemarie.solon.com (Peter Seebach) writes...
  14. >I guess I thought I knew C, but maybe not.  The following program compiles
  15. >without error with
  16. >gcc -g -O -Wa,ll -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes
  17. >but doesn't print 3!  I thought scanf and printf were asymptotic.
  18.  
  19.  
  20. It would help if you posted the _real_ code so we would know there weren't any
  21. typos...
  22.  
  23. >    #include <stdio.h>
  24. >    int main(void) {
  25. >        int i = 0;
  26. >        (void) sscanf, "3", "%d", i;
  27.  
  28. This won't compile as is - it needs some parentheses, like:
  29.         (void) sscanf("3", "%d", i);
  30. If this is what your real code says, then you need to change it to:
  31.         (void) sscanf("3", "%d", &i);
  32. Since sscanf() must change i, you have to pass i's _address_, using &i.
  33.  
  34.  
  35. >        (void) printf, "%d", i;
  36. this must have some parentheses as well:
  37.         (void) printf("%d", i);
  38.  
  39. The arguments for the sscanf() and printf() families are similar, but not
  40. identical - scanf() needs the _address_ of its arguments, and printf() does
  41. not.  There are also some differences in the format specifiers.
  42.  
  43.  
  44. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  45. Internet: bennett@triumf.ca         | of one another only when one can be
  46. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  47. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  48. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  49. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  50.  
  51.